<template>
    <view class="content">
        <u-navbar :background="background" title="陪伴师中心" title-color="#fff" :border-bottom="false" :immersive="true"
            :is-back="false" back-icon-color="#fff">
            <view class="u-p-l-20" @click="back">
                <u-icon name="arrow-left" color="#fff" size="36"></u-icon>
            </view>
        </u-navbar>
        
        <view class="wrapper" :style="{marginTop: statusBar + 42 + 'px'}">
            <view class="top">
                <view class="item-r-t">
                    <view class="name">{{data.name}}</view>
                    <view class="real">已实名</view>
                    <u-rate :count="data.star" v-model="data.star" active-color="#fec427" size="26" gutter="5" disabled></u-rate>
                    <!-- <u-icon name="star-fill" color="#fec427" size="28"></u-icon> -->
                    <!-- <view class="star-num">{{data.star}}</view> -->
                </view>
                <view class="switch1" :class="data.work_status == 1?'switchAct1':'switchAct2'" @click="onOff()">
                	<view class="switch-small"></view>
                	<view class="switch-text">
                		{{data.work_status == 1?'接单':'休息'}}
                	</view>
                </view>
            </view>
            <view class="nav">
                <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">待接单</view>
                <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">服务中</view>
                <view class="nav-i" :class="{active : type == 4}" @click="chooseNav(4)">已完成</view>
            </view>
            
            <view class="box">
                <view class="item" v-for="(item, index) in list" :key="index" @click="$gTo(`/serve/pages/order/details?id=${item.id}`)">
                    <!-- delay>0 有延期 -->
                    <view class="delay" v-if="type == 3 && delay > 0">服务延期</view>
                    
                    <view class="title">{{item.items}}</view>
                    <view class="time">{{item.week}}</view>
                    <view class="item-down">
                        <image :src="IMAGEURL + 'static/icon/icon_01.png'" class="icon-01"></image>
                        <view class="studen">{{item.name}}</view>
                        <view class="male" v-if="item.gender == 1">男</view>
                        <view class="female" v-if="item.gender == 2">女</view>
                        <view class="age">{{item.age}}岁</view>
                    </view>
                    <view class="btns" v-if="type == 2">
                        <view class="btn1">确认接单</view>
                    </view>
                </view>
                
                <view style="height: 94rpx;padding-top: 30rpx;">
                    <u-loadmore :status="status" v-if="status != 'loadmore'" />
                </view>
            </view>
            
            <!-- 正在服务单，订单详情 不传id 进入已经开始的服务详情 -->
            <image src="../../static/image/s_img_09.png" class="s-img-09" v-if="type == 3 && list.length > 0"
                 @click="$gTo(`/serve/pages/order/details`)"></image>
        </view>
        
        <view class="tabbar">
            <view class="tab" @click="change(1)">
                <image src="../../static/icon/s_tab_02.png" class="s-tab-01" v-if="tab == 1"></image>
                <image src="../../static/icon/s_tab_01.png" class="s-tab-01" v-else></image>
                <view :class="{tabActive : tab == 1}">首页</view>
            </view>
            <view class="tab" @click="change(2)">
                <image src="../../static/icon/s_tab_04.png" class="s-tab-01" v-if="tab == 2"></image>
                <image src="../../static/icon/s_tab_03.png" class="s-tab-01" v-else></image>
                <view :class="{tabActive : tab == 2}">实时</view>
            </view>
            <view class="tab" @click="change(3)">
                <image src="../../static/icon/s_tab_06.png" class="s-tab-01" v-if="tab == 3"></image>
                <image src="../../static/icon/s_tab_05.png" class="s-tab-01" v-else></image>
                <view :class="{tabActive : tab == 3}">社群</view>
            </view>
            <view class="tab" @click="change(4)">
                <image src="../../static/icon/s_tab_08.png" class="s-tab-01" v-if="tab == 4"></image>
                <image src="../../static/icon/s_tab_07.png" class="s-tab-01" v-else></image>
                <view :class="{tabActive : tab == 4}">我的</view>
            </view>
        </view>
    </view>
</template>

<script>
    import { IMAGEURL } from '@/static/js/common.js';
    export default {
        data() {
            return {
                IMAGEURL,
                statusBar: 0,
                background: { backgroundColor: 'rgba(36,38,43,1)' },
                tab: 1, //1首页 2实时 3社群 4我的
                type: 2,//1未支付 2待接单 3服务中 4已完成
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                data: {},
            };
        },
        onLoad() {
            let _this = this;
            //状态栏高度
            uni.getSystemInfo({
            	success: function(res) {
            		_this.statusBar = res.statusBarHeight;
            	}
            });
        },
        onShow() {
            this.page = 1
            this.list = []
            this.status = 'loadmore'
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            // 接单、休息
            onOff() {
                this.$ajax('work_status', {
                	user_token: this.$getSync('userToken'),
                }).then(ret => {
                	if (ret.success == 1000) {
                        // work_status 1接单 2休息
                        this.data.work_status = this.data.work_status == 1 ? 2 : 1 
                	} else {
                		this.$toast(ret.msg);
                	}
                });
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.page = 1
                this.list = []
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('order_list', {
            		user_token: this.$getSync('userToken'),
            		page: this.page,
            		limit: 10,
                    type: 3,//类型 1全部订单 2周期服务 3服务人员首页
                    status: this.type,//1未支付 2待接单 3服务中 4已完成
            	}).then(ret => {
            		if (ret.success == 1000) {
                        this.data = ret.detail
                        
            			if (ret.detail && ret.detail.orders && ret.detail.orders.length > 0) {
            				this.list = this.list.concat(ret.detail.orders);
            				this.page++;
            				this.status = 'loadmore'
            			} else {
            				this.status = 'nomore'
            			}
            		} else {
            			this.$toast(ret.msg);
            		}
            	});
            },
            
            // 切换服务人员底部导航
            change(num) {
                if (num == 1) {
                    return
                    // this.$cTo(`/serve/pages/tab/home`)
                } else if (num == 2) {
                    this.$cTo(`/serve/pages/tab/realtime`)
                } else if (num == 3) {
                    this.$cTo(`/serve/pages/tab/friends`)
                } else if (num == 4) {
                    this.$cTo(`/serve/pages/tab/us`)
                }
            },
            
            back() {
                uni.switchTab({
                    url: '/pages/tabbar/mine'
                })
            },
            
            onPageScroll: function(e) {
            	//nvue暂不支持滚动监听，可用bindingx代替
            	// console.log("滚动距离为：" + e.scrollTop);
            	let a = e.scrollTop * 0.05;
            	if (a > 1) {
            		a = 1;
            	}
                this.background.backgroundColor = 'rgba(36,38,43,1)';
            	// if (e.scrollTop == 0) {
            	// 	this.background.backgroundColor = 'rgba(0,0,0,0)';
            	// } else {
            	// 	this.background.backgroundColor = 'rgba(0,0,0,' + a + ')';
            	// }
            },
        }
    };
</script>

<style lang="scss">
    
    
    
    
    
    page{
        background-color: #f5f5f5;
    }
    .content{
        padding-bottom: 120rpx;
    }
    .tabbar{
        width: 100vw;
        height: 115rpx;
        background-color: #fff;
        border-top: 2rpx solid #e6e6e6;
        display: flex;
        justify-content: space-around;
        align-items: center;
        position: fixed;
        bottom: 0;
        left: 0;
        z-index: 999;
    }
    .tab{
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        font-size: 24rpx;
    }
    .s-tab-01{
        width: 50rpx;
        height: 50rpx;
    }
    .tabActive{
        color: #f29700;
    }
    
    .top{
        padding: 30rpx 35rpx;
        background-color: #24262b;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .item-r-t{
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    .name{
        max-width: 275rpx;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 50rpx;
        // font-weight: bold;
        color: #fff;
    }
    .real{
        padding: 7rpx 8rpx;
        background-color: #000;
        border-radius: 6rpx;
        font-size: 20rpx;
        color: #feeca8;
        line-height: 1;
        margin: 0 10rpx;
    }
    .star-num{
        font-size: 28rpx;
        // font-weight: bold;
        padding-left: 6rpx;
        color: #fec427;
    }
    
    .switch1 {
    	width: 140rpx;
    	height: 54rpx;
    	background: #9eafc2;
    	position: relative;
    	border-radius: 50rpx;
    
    	.switch-small {
    		width: 46rpx;
    		height: 46rpx;
    		position: absolute;
    		left: 4rpx;
    		top: 4rpx;
    		background: white;
    		border-radius: 50%;
    	}
    
    	.switch-text {
    		color: white;
    		position: absolute;
    		left: 20rpx;
    		font-weight: normal;
    		top: 0rpx;
    		font-size: 24rpx;
    		line-height: 54rpx;
    	}
    }
    
    .switchAct2 {
    	background: #9eafc2;
    
    	.switch-small {
    		left: 4rpx !important;
    		transition: 0.3s;
    	}
    
    	.switch-text {
    		left: 60rpx !important;
    	}
    }
    
    .switchAct1 {
    	background: #f29700;
    
    	.switch-small {
    		left: 91rpx !important;
    		transition: 0.3s;
    	}
    
    	.switch-text {
    		left: 30rpx !important;
    	}
    }
    
    .nav{
        background-color: #24262b;
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    .nav-i{
        font-size: 28rpx;
        color: #bcbdbe;
        padding: 20rpx 0;
    }
    .active{
        font-size: 32rpx;
        color: #fff;
        font-weight: bold;
        position: relative;
    }
    .active::after{
        display: block;
        content: '';
        width: 32rpx;
        height: 8rpx;
        background-color: #f29700;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
    }
    
    
    .box{
        padding: 20rpx;
    }
    .item{
        padding: 35rpx 25rpx;
        margin-bottom: 20rpx;
        background-color: #fff;
        border-radius: 15rpx;
        position: relative;
    }
    .delay{
        width: 140rpx;
        height: 39rpx;
        font-size: 24rpx;
        color: #fff;
        text-align: center;
        line-height: 39rpx;
        background: linear-gradient(to right, #fd7c39, #fb4c1a);
        border-radius: 0 15rpx 0 15rpx;
        position: absolute;
        right: 0;
        top: 0;
    }
    .s-img-09{
        width: 136rpx;
        height: 139rpx;
        position: absolute;
        right: 5rpx;
        bottom: 130rpx;
        z-index: 9;
    }
    .title{
        font-size: 34rpx;
        font-weight: bold;
        word-break: break-all;
        white-space: pre-line;
    }
    .time{
        font-size: 26rpx;
        color: #8e8e8e;
        padding-top: 10rpx;
    }
    .item-down{
        display: flex;
        justify-content: flex-start;
        align-items: center;
        padding-top: 20rpx;
    }
    .icon-01{
        width: 37rpx;
        height: 37rpx;
        margin-right: 15rpx;
    }
    .studen{
        font-size: 32rpx;
        font-weight: bold;
        padding-right: 15rpx;
    }
    .male{
        width: 34rpx;
        height: 34rpx;
        border-radius: 5rpx;
        background-color: #edf6ff;
        font-size: 26rpx;
        color: #2d96fa;
        text-align: center;
        line-height: 34rpx;
    }
    .female{
        width: 34rpx;
        height: 34rpx;
        border-radius: 5rpx;
        background-color: #ffeeed;
        font-size: 26rpx;
        color: #ff5748;
        text-align: center;
        line-height: 34rpx;
    }
    .age{
        font-size: 26rpx;
        color: #727272;
        padding-left: 15rpx;
    }
    
    .down{
        padding-top: 10rpx;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .tip{
        font-size: 24rpx;
        color: #ff5748;
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }
    .tip-icon{
        width: 26rpx;
        height: 26rpx;
        margin-right: 10rpx;
    }
    .btns{
        display: flex;
        justify-content: flex-end;
        align-items: center;
    }
    .btns>view{
        font-size: 28rpx;
        padding: 10rpx 20rpx;
        border-radius: 10rpx;
        margin-left: 20rpx;
        box-sizing: border-box;
    }
    .btn1{
        color: #fff;
        background-color: #f29700;
    }
    .btn2{
        border: 2rpx solid #eeeeee;
    }
    .btn3{
        background-color: #fffcf8;
        border: 2rpx solid #f29700;
    }
    

</style>
